package com.nz.net.hays.www;

import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.ViewGroup.LayoutParams;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.TableRow;
import android.widget.Toast;

public class DynamicLocationActivity extends Activity implements OnCheckedChangeListener {

	
	JSONParser jsonParser = new JSONParser();
	private static String url = "http://hays.byethost6.com/hayslogin.php";
	private static final String TAG_SUCCESS = "success"; 
	int flag =2,counter=0,i=0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		/*StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
		.detectDiskReads().detectDiskWrites().detectNetwork()
		.penaltyLog().build());*/
		super.onCreate(savedInstanceState);
		setContentView(R.layout.final_location);
		checkboxcode();
	}
	
	// Dynamic Checkbox Creation
	@SuppressWarnings("deprecation")
	private void checkboxcode() {
		try {
			int Array_Count_Island=0,Array_Count_State=0,Array_Count_City=0;
			String[] Str_Island = {"North Island","South Island"}; 
			//String[][] Str_State ={{"North Island","All Auckland"},{"North Island","Wellington"},{"South Island","Christchurch"},{"South Island","Dunedin"},{"South Island","Regional"}};
			String[]Str_State ={"All Auckland","Wellington","Christchurch","Dunedin","Regional"};
			
			String[]Str_City={"Auckland CBD","North Auckland","South Auckland"};

			Array_Count_Island=Str_Island.length;
			Array_Count_State=Str_State.length;
			Array_Count_City=Str_City.length;
			//Array_Count=3;
			
			LinearLayout my_layout = (LinearLayout)findViewById(R.id.finalinearlayout);
			LinearLayout my_layout_child = (LinearLayout)findViewById(R.id.finalinearlayoutchild);
			for (i=0; i < Array_Count_Island; i++) 
			{
			    TableRow row =new TableRow(this);
			    row.setId(i);
			    row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
			    CheckBox checkBox = new CheckBox(this);
			    checkBox.setOnCheckedChangeListener(this);
			    checkBox.setId(i);
			    checkBox.setText(Str_Island[i]);
			    row.addView(checkBox);  
			    my_layout.addView(row);
			    	for(int j=1;j<=Array_Count_State;j++)
			    	{
			    		while(flag!=0)
			    		{
			    			row =new TableRow(this);
						    row.setId(j+counter);
						    row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
							   
						    checkBox = new CheckBox(this);
						    checkBox.setOnCheckedChangeListener(this);
						    checkBox.setId(j+counter);
						    checkBox.setText(Str_State[j+counter-1]);
						    
						    row.addView(checkBox); 
						    my_layout.addView(row);
						    
						    my_layout.bringChildToFront(my_layout_child);
						    flag--;
			    		}
			    	
			    		 if(flag==0)
						    {
						    	counter=2;
						    	flag=4;
						    	//i=1;
						    	break;
						    	
						    }
				     
						 
			    	}
			    	
			 
			}
		} catch (Exception e) {
		
			e.printStackTrace();
			String msg=e.getMessage();
			Toast.makeText(DynamicLocationActivity.this,msg, Toast.LENGTH_LONG).show();
			
			
		}
		
			
		}
// Creation Close

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		// TODO Auto-generated method stub
		
	}
}
